package com.infosys.cabplanningdao.address.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.infosys.cabplanning.common.domain.Address;
import com.infosys.cabplanningdao.address.dao.AddressDAO;

public class AddressDAOImpl extends JdbcDaoSupport implements AddressDAO {

	@Override
	public List<Address> getAllAddress() {
		String sql = "SELECT address_id, house_no, street, city,"
				+ "country, zip_code FROM hackathon.address";

		List<Address> addressList = getJdbcTemplate().query(sql,
				new AddressRowMapper());
		return addressList;
	}

	@Override
	public Address getAddressById(int addressId) {
		String sql = "SELECT address_id, house_no, street, city,"
				+ "country, zip_code FROM hackathon.address WHERE address_id = ?";
		Address address = (Address) getJdbcTemplate().queryForObject(sql,
				new Object[] { addressId }, new AddressRowMapper());
		return address;
	}

}
